#include "cgic.h"
#include <glib.h>
#include "MsgUntils.h"
#include "global.h"

cgiMain(){
    char *gatewayip[128];
    char *location[128];

    cgiFormString("gatewayip",gatewayip,128);
    cgiFormString("location",location,128);

    GKeyFile *configiniPath = g_key_file_new();
    if(!g_key_file_load_from_file(configiniPath,"./config.ini",G_KEY_FILE_NONE,NULL)){
      g_warning("load config.ini error!");
      return -1;
    }
    gchar *path =g_key_file_get_string(configiniPath,"config","devinfo_path",NULL);
    g_key_file_free(configiniPath);

    GKeyFile *configPath = g_key_file_new();
    g_key_file_set_string(configPath,"config","gatewayip",gatewayip);
    g_key_file_set_string(configPath,"config","location",location);
    g_key_file_save_to_file(configPath,path,NULL);
    g_key_file_free(configPath);

    int mqId = getMsgQueue(PATHNAME_BOA_MAIN,PROCESS_ID_BOA_MAIN);
    if (mqId == -1)
    {
      perror("create mq error");
      return -1;
    }
    Message msg={
      .type=1,
      .text="data1"
    };
    int sendSize = sendMsg(mqId,&msg,strlen(msg.text)+1);



    cgiHeaderContentType("text/html");
	/* Top of the page */
	fprintf(cgiOut, "<HTML><HEAD><meta charset='UTF-8'>\n");
	fprintf(cgiOut, "<TITLE>cgic test</TITLE></HEAD>\n");
	fprintf(cgiOut, "<BODY><H1>%s</H1>\n","我是曹刚");
    fprintf(cgiOut, "</BODY></HTML>\n");
  
}